#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
using namespace std;

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int sum = 0, ret = INT_MAX;
        int left = 0, right = 0;
        while (right < nums.size())
        {
            sum += nums[right];
            right++;
            
            while (sum >= target)
            {
                ret = min(ret, right - left);
                sum -= nums[left];
                left++;
            }
        };
        return ret == INT_MAX ? 0 : ret;
    }
};